//
//  UIImage+Extension.swift
//  PhotoSeletor
//
//  Created by 陈锦聪 on 16/4/3.
//  Copyright © 2016年 Coco. All rights reserved.
//

import UIKit

extension UIImage {
    
    func scaleImage(newWidth: CGFloat = 300) -> UIImage {
        if size.width < newWidth {
            return self
        }
        let newHeight = newWidth * size.height / size.width
        let newSize = CGSize(width: newWidth, height: newHeight)
        UIGraphicsBeginImageContext(newSize)
        drawInRect(CGRect(origin: CGPointZero, size: newSize))
        let newImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return newImage
    }
}
